<?php

namespace console\controllers;

use Yii;
use yii\helpers\Console;
use yii\db\Query;

/**
 * TicketController
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @since 2.0
 */
class TicketController extends \yii\console\Controller {

    public function batchSourceData($name) {
        $db = Yii::$app->olddb;
        $query = (new Query)->from('{{%' . $name . '}}')->limit(10);
        foreach ($query->each(100, $db) as $row) {
            $this->trans($row);
        }
    }

    public function trans($row) {
        var_dump($row);
    }

    /**
     * @return mixed
     */
    public function actionIndex() {
//        $this->batchSourceData('cms_article');
        $fruit = array('a' => 'apple', 'b' => 'banana', 'cranberry');

        reset($fruit);
        while (list($key, $val) = each($fruit)) {
            echo "$key => $val\n";
        }
        /* @var $olddb \console\db\Connection */
//        $olddb = Yii::$app->olddb;
//
//        $query = (new Query)->from('{{%cms_article}}');
//        foreach ($query->each(100, $olddb) as $row) {
//            var_dump($row);
//            if ($row['status'] < 1) {
//                continue;
//            }
//        }
//        $data = $connection->createCommand('INSERT INTO newauser SELECT * FROM ln_app_cms_article;')->queryOne();
//        $sql = 'SELECT * FROM ln_app_cms_article';
//        $connection->createCommand($sql)->queryAll();
//        var_dump($data);
//        Console::output();
    }

}
